//
//  YMEmoticonPageView.swift
//  YMWeiBo
//
//  Created by mimi on 16/7/29.
//  Copyright © 2016年 mimi. All rights reserved.
//

import UIKit

private let YMEmoticonPageViewCellID = "YMEmoticonPageViewID"

class YMEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK : -设置视图
    private func setupUI() {
//        backgroundColor = RandomColor()
        dataSource = self
        
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        layout.itemSize = CGSizeMake(SCREENW, 216 - 37)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .Horizontal
        
        registerClass(YMYMEmoticonPageViewCell.self, forCellWithReuseIdentifier: YMEmoticonPageViewCellID)
    }
    
    
    
}

extension YMEmoticonPageView:UICollectionViewDataSource{
    //组
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return YMEmoticonTools.sharedTools.allEmoticons.count
    }
    //行
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return YMEmoticonTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(YMEmoticonPageViewCellID, forIndexPath: indexPath) as! YMYMEmoticonPageViewCell
        
        cell.emoticon = YMEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        
        cell.indexPath = indexPath
        return cell
    }
    
}







